"""
@ProjectName : CourseManagementSystem
@File        : course_ui.py
@Author      : WorldWind(1772830365@qq.com)
@Address     : ChangSha - BoWeiFeng
@Date        : 2025/7/17 下午1:35
"""
from courses.course import Course
from courses.course_service import CourseService


class CourseUI:
    def __init__(self):
        self.service = CourseService()
        print(f'This is __init__ method. {self.get_class_name()} class startup')

    def add(self):
        course_no = input('请输入新增课程号:')
        course_name = input('请输入新增课程名称:')
        max_score = input('请输入该课程可获得最高分数:')
        min_sroce = input('请输入该课程可获得最低分数:')
        course = Course()
        course.course_no = course_no
        course.course_name = course_name
        course.max_score = max_score
        course.min_sorce = min_sroce
        record = self.service.add(course)
        return record

    def delete(self):
        id = input('请输入您想删除数据的课程id(测试)')
        record = self.service.delete(id)
        return record

    def update(self):
        course_no = input('请输入修改后课程号:')
        course_name = input('请输入修改后课程名称:')
        max_score = input('请输入修改后该课程可获得最高分数:')
        min_sroce = input('请输入修改后该课程可获得最低分数:')
        id = input('请输入想要修改的课程id:')
        course = Course()
        course.course_no = course_no
        course.course_name = course_name
        course.max_score = max_score
        course.min_sorce = min_sroce
        course.id = id
        record = self.service.update(course)
        return record

    def searchAll(self):
        return self.service.searchAll()

    def searchCourseByName(self):
        course_name = input('请输入您想要查询课程的课程名(支持模糊查询):')
        return self.service.searchCourseByName(course_name)

    @classmethod
    def get_class_name(cls):
        return cls.__name__

    def __del__(self):
        print(f'This is __del__ method. The {self.get_class_name()} class has been recycled')


if __name__ == '__main__':
    ui = CourseUI()
    # print(ui.add())
    # print(ui.delete())
    # print(ui.update())
    # print(ui.searchAll())
    # print(ui.searchCourseByName())
